﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Studio7i.Dominio;
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations;

namespace Studio7i.Persistencia.EF.ORM
{
    public class InstrumentoMapping : EntityTypeConfiguration<Instrumento>
    {
        public InstrumentoMapping()
            : base()
        {
            ToTable("instrumento");
            HasKey(i => i.Codigo);
            Property(i => i.Codigo)
                .HasColumnName("codigo")
                .IsRequired()
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
            Property(i => i.Tipo)
                .HasColumnName("tipo")
                .IsRequired();
            Property(i => i.Marca)
                .HasColumnName("marca")
                .IsRequired();
            Property(i => i.Modelo)
                .HasColumnName("modelo")
                .IsRequired();
            Property(i => i.AnhoFabricacion)
                .HasColumnName("anho_fabricacion")
                .IsRequired();
            Property(i => i.Caracteristicas)
                .HasColumnName("caracteristicas")
                .IsRequired();
            Property(i => i.CostoAlquiler)
                .HasColumnName("costo_alquiler")
                .IsRequired();
            HasMany<Sala>(i => i.Salas)
                .WithMany(s => s.Instrumentos)
                .Map(m => m.ToTable("sala_instrumento")
                    .MapLeftKey("instrumento")
                    .MapRightKey("sala"));
        }
    }
}